import CryptoJS from "crypto-js";

export default {
	
	encrypt(word) {
	// encrypt(word, keyStr, ivStr) {
	    // keyStr = keyStr ? keyStr : "1234567";
	    // ivStr = ivStr ? ivStr : "123456789";
		var keyStr = "c95c254ebc6f"+"11eaa605000c"+"29b99d67";
		var ivStr = "12345"+"678900"+"00000";
	    let key = CryptoJS.enc.Utf8.parse(keyStr);
	    //console.log(key);
	    let iv = CryptoJS.enc.Utf8.parse(ivStr);
	    let src = CryptoJS.enc.Utf8.parse(word);
	    let encrypted = CryptoJS.AES.encrypt(src, key, {
	      iv,
	      mode: CryptoJS.mode.CBC,
	      padding: CryptoJS.pad.Pkcs7
	    });
	    // console.log(CryptoJS.enc.Base64.stringify(encrypted.ciphertext),encrypted.toString());
	    return encrypted.ciphertext.toString();
	},
	// 解密
	// decrypt(word, keyStr, ivStr){
	decrypt(word){
	   var keyStr = "c95c254ebc6f"+"11eaa605000c"+"29b99d67";
	   var ivStr = "12345"+"678900"+"00000";
	   
	    var key = CryptoJS.enc.Utf8.parse(keyStr);
	    let iv = CryptoJS.enc.Utf8.parse(ivStr);
	    let base64 = CryptoJS.enc.Hex.parse(word);
	    let src = CryptoJS.enc.Base64.stringify(base64);
	    //let src = CryptoJS.enc.Utf8.parse(word);
	    var decrypt = CryptoJS.AES.decrypt(src, key, {
	      iv,
	      mode: CryptoJS.mode.CBC,
	      padding: CryptoJS.pad.Pkcs7
	    });
	    console.log(decrypt);
	    // console.log(decrypt.toString(CryptoJS.enc.Utf8),(decrypt.toString(CryptoJS.enc.Utf8)).toString(),CryptoJS.enc.Utf8.stringify(decrypt).toString())
	    return decrypt.toString(CryptoJS.enc.Utf8);
	},
	
	getSourceText(){
	    return "Ddt000000";
	},
	
	getKeyText(){
	    var key = "c95c254ebc6f"+"11eaa605000c"+"29b99d67";
	    return key;
	},
	
	getIvr(){
	    return "12345"+"678900"+"00000";
	},
	// var word = getSourceText();
	// console.log(word);
	// var key = getKeyText();
	// console.log(key);
	// var ivr = getIvr();
	// console.log(ivr);
	
	
	// var enced = encrypt(word,key,ivr);
	
	// console.log("Enced: = " + enced);
	
	
	// var pass = enced.toUpperCase();
	// console.log(pass);
	// var deced = decrypt(pass,key,ivr);
	
	// console.log(deced);
} 

